package maquina;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import monitor.TipoMonitorado;

public class ComponentProperties {

	private Properties properties;
	
	public void setComponentInformations(int componente, String login, String password, String server){
		 File file = null;      
		 
		 //Select the appropriate property file...
		 if(componente != TipoMonitorado.OPENFIRE){
			if(componente == TipoMonitorado.PEER){
				file = new File(LocalProperties.peerPath+"//peer.properties");
			} else if(componente == TipoMonitorado.BROKER){
				file = new File(LocalProperties.peerPath+"//broker.properties");
			} else if(componente == TipoMonitorado.WORKER){
				file = new File(LocalProperties.peerPath+"//worker.properties");
			}
	
			//Initialize the property 
		    properties = new Properties();
		    FileInputStream fis = null;
		    try {  
		       fis = new FileInputStream(file);    
		       
		       properties.load(fis);
		       
		       //Set the essential properties to start a component correctly
		       properties.setProperty("commune.xmpp.username", login);
		       properties.setProperty("commune.xmpp.password", password); 
		       properties.setProperty("commune.xmpp.servername", server); 
		       
		       fis.close();  
		    }  
		    catch (IOException ex) {  
		       System.out.println(ex.getMessage());  
		       ex.printStackTrace();  
		    }
		 }
	}
	
}
